home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / drop-shadow.scm.z / drop-shadow.scm
Encoding:
GIMP Script-Fu Script  |  1999-07-21  |  5.5 KB  |  197 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.  
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ;
  16. ; drop-shadow.scm   version 1.02   12/13/97
  17. ;
  18. ; CHANGE-LOG:
  19. ; 1.00 - initial release
  20. ; 1.01 - fixed the problem with a remaining copy of the selection
  21. ; 1.02 - some code cleanup, no real changes
  22. ;
  23. ;
  24. ; Copyright (C) 1997 Sven Neumann (neumanns@uni-duesseldorf.de)
  25. ;  
  26. ; Adds a drop-shadow of the current selection or alpha-channel. 
  27. ;
  28. ; This script is derived from my script add-shadow, which has become 
  29. ; obsolete now. Thanks to Andrew Donkin (ard@cs.waikato.ac.nz) for his 
  30. ; idea to add alpha-support to add-shadow.
  31.  
  32.   
  33. (define (script-fu-drop-shadow image 
  34.                    drawable 
  35.                    shadow-transl-x 
  36.                    shadow-transl-y 
  37.                    shadow-blur
  38.                    shadow-color
  39.                    shadow-opacity
  40.                    allow-resize)
  41.   (let* ((shadow-blur (max shadow-blur 0))
  42.      (shadow-opacity (min shadow-opacity 100))
  43.      (shadow-opacity (max shadow-opacity 0))
  44.      (type (car (gimp-drawable-type-with-alpha drawable)))
  45.      (image-width (car (gimp-image-width image)))
  46.      (image-height (car (gimp-image-height image)))
  47.      (old-bg (car (gimp-palette-get-background)))
  48.      (from-selection 0)
  49.      (active-selection 0)
  50.      (shadow-layer 0))
  51.  
  52.   (gimp-image-disable-undo image)
  53.   
  54.   (gimp-layer-add-alpha drawable)
  55.   (if (= (car (gimp-selection-is-empty image)) TRUE)
  56.       (begin
  57.     (gimp-selection-layer-alpha image drawable)
  58.     (set! from-selection FALSE))
  59.       (begin 
  60.     (set! from-selection TRUE)
  61.     (set! active-selection (car (gimp-selection-save image)))))
  62.   
  63.   (let* ((selection-bounds (gimp-selection-bounds image))
  64.      (select-offset-x (cadr selection-bounds))
  65.      (select-offset-y (caddr selection-bounds))
  66.      (select-width (- (cadr (cddr selection-bounds)) select-offset-x))
  67.      (select-height (- (caddr (cddr selection-bounds)) select-offset-y))
  68.   
  69.      (shadow-width (+ select-width (* 2 shadow-blur)))
  70.      (shadow-height (+ select-height (* 2 shadow-blur)))
  71.  
  72.      (shadow-offset-x (- select-offset-x shadow-blur))
  73.      (shadow-offset-y (- select-offset-y shadow-blur)))
  74.  
  75.     (if (= allow-resize TRUE)
  76.     (let* ((new-image-width image-width)
  77.            (new-image-height image-height)
  78.            (image-offset-x 0)
  79.            (image-offset-y 0))
  80.  
  81.       (if (< (+ shadow-offset-x shadow-transl-x) 0)
  82.           (begin
  83.         (set! image-offset-x (- 0 (+ shadow-offset-x 
  84.                          shadow-transl-x)))
  85.         (set! shadow-offset-x (- 0 shadow-transl-x))
  86.         (set! new-image-width (- new-image-width image-offset-x))))
  87.  
  88.       (if (< (+ shadow-offset-y shadow-transl-y) 0)
  89.           (begin
  90.         (set! image-offset-y (- 0 (+ shadow-offset-y 
  91.                          shadow-transl-y)))
  92.         (set! shadow-offset-y (- 0 shadow-transl-y))
  93.         (set! new-image-height (- new-image-height image-offset-y))))
  94.  
  95.       (if (> (+ (+ shadow-width shadow-offset-x) shadow-transl-x) 
  96.          new-image-width)
  97.           (set! new-image-width 
  98.             (+ (+ shadow-width shadow-offset-x) shadow-transl-x)))
  99.  
  100.       (if (> (+ (+ shadow-height shadow-offset-y) shadow-transl-y) 
  101.          new-image-height)
  102.           (set! new-image-height
  103.             (+ (+ shadow-height shadow-offset-y) shadow-transl-y)))
  104.  
  105.       (gimp-image-resize image
  106.                  new-image-width 
  107.                  new-image-height 
  108.                  image-offset-x 
  109.                  image-offset-y)))
  110.  
  111.  
  112.     (set! shadow-layer (car (gimp-layer-new image 
  113.                         shadow-width 
  114.                         shadow-height 
  115.                         type
  116.                         "Drop-Shadow" 
  117.                         shadow-opacity
  118.                         NORMAL)))
  119.     (gimp-layer-set-offsets shadow-layer 
  120.                 shadow-offset-x
  121.                 shadow-offset-y))
  122.  
  123.   (gimp-drawable-fill shadow-layer TRANS-IMAGE-FILL)
  124.   (gimp-palette-set-background shadow-color)
  125.   (gimp-edit-fill image shadow-layer)
  126.   (gimp-selection-none image)
  127.   (gimp-layer-set-preserve-trans shadow-layer FALSE)
  128.   (if (> shadow-blur 0) (plug-in-gauss-rle 1 
  129.                        image 
  130.                        shadow-layer 
  131.                        shadow-blur 
  132.                        TRUE 
  133.                        TRUE))
  134.   (gimp-image-add-layer image shadow-layer -1)
  135.   (gimp-layer-translate shadow-layer shadow-transl-x shadow-transl-y)
  136.  
  137.   (if (= from-selection TRUE)
  138.       (begin
  139.     (gimp-selection-load image active-selection)
  140.     (gimp-edit-clear image shadow-layer)
  141.     (gimp-image-remove-channel image active-selection)))
  142.  
  143.   (if (and 
  144.        (= (car (gimp-layer-is-floating-sel drawable)) 0)
  145.        (= from-selection FALSE))
  146.       (gimp-image-raise-layer image drawable))
  147.  
  148.   (gimp-image-set-active-layer image drawable)
  149.   (gimp-palette-set-background old-bg)
  150.   (gimp-image-enable-undo image)
  151.   (gimp-displays-flush)))
  152.  
  153. (script-fu-register "script-fu-drop-shadow" 
  154.             "<Image>/Script-Fu/Shadow/Drop-Shadow"
  155.             "Add a drop-shadow of the current selection or 
  156.                      alpha-channel"
  157.             "Sven Neumann (neumanns@uni-duesseldorf.de)"
  158.             "Sven Neumann"
  159.             "12/13/1997"
  160.             "RGB RGBA GRAY GRAYA"
  161.             SF-IMAGE "Image" 0
  162.             SF-DRAWABLE "Drawable" 0
  163.             SF-VALUE "X offset" "8"
  164.             SF-VALUE "Y offset" "8"
  165.             SF-VALUE "Blur Radius" "15"
  166.             SF-COLOR "Color" '(0 0 0)
  167.             SF-VALUE "Opacity" "80"
  168.             SF-TOGGLE "Allow Resizing" TRUE) 
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.